package com.example.Controller;

import com.example.entity.*;
import com.example.service.UserService;
import com.example.service.impl.AdminuserServiceImpl;
import com.example.service.impl.OrdersServiceImpl;
import com.example.service.impl.UserServiceImpl;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.rmi.server.UID;
import java.util.ArrayList;

@Controller
@RequestMapping("/admin")
public class OrdersCtrl {
    @Resource
    OrdersServiceImpl ordersService;

    @Resource
    UserServiceImpl userService;

    @RequestMapping (value = "/orders" ,method = {RequestMethod.GET , RequestMethod.POST})
    public String findAllOrders(Model model, @RequestParam(value = "pageNum",required = false, defaultValue = "1") Integer pageNum
            , @RequestParam(value = "pageSize",required = false, defaultValue = "4") Integer pageSize){
        PageInfo<Orders> ordersList =  ordersService.queryAll(pageNum,pageSize);
        model.addAttribute("ordersList",ordersList);
        System.out.println(ordersList);
        return "ordersList";
    }
    @GetMapping("/delOrders/{id}")
    public String delOrders(@PathVariable("id") int id, Model model){
        int m = ordersService.deleteByID(id);
        model.addAttribute("msg","删除成功");
        return "forward:/admin/orders";
    }
    @GetMapping("/orders/{id}")
    public String getOrdersById(@PathVariable("id") int id,Model model){
        Orders orders = ordersService.findById(id);
        model.addAttribute("orders",orders);
        return "ordersEdit";
    }
    @PostMapping("/editOrders")
    public String addGoods(Orders orders,Model model){

        int u = ordersService.update(orders);
        model.addAttribute("msg","商品信息更新成功！");
        return "forward:/admin/orders";
    }
    @GetMapping("/gotoAddOrders")
    public String gotoAddorders(){
        return "ordersAdd";
    }
    @PostMapping("/addOrders")
    public String addOrders(Orders orders){
        int y = ordersService.insert(orders);
        return "forward:/admin/orders";
    }
}
